<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var str = "       a  aa       ";
      // 去除两侧的空格
      str = str.trim();
      console.log(str); // 中间的空格不会去除
    </script>
  </body>
</html>
